import mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.User;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

//主类
public class MybatisDemo03 {
    public static void main(String[] args) throws IOException {
        //操作Mybatis的4个步骤
        //1.加载配置文件，创建工厂类
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        //2.创建sqlSession
        SqlSession sqlSession = factory.openSession();

        //3.执行SQL语句
        //List<User> userList = sqlSession.selectList("test.selectAll");
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        //List<User> userList = userMapper.selectAll();
        User oneUser = userMapper.selectOne(2);
        System.out.println(oneUser);

        //4.关闭sqlSession
        sqlSession.close();
//        sqlSession.close();
//        for (User user : userList) {
//            System.out.println("user");
        }
    }

